package com.wudl.sparksql


import org.apache.spark.rdd.RDD
import org.apache.spark.sql.types.{IntegerType, StringType, StructField, StructType}
import org.apache.spark.sql.{DataFrame, Row, SparkSession}


/**
 *
 */
object RddTo2Df {

  def main(args: Array[String]): Unit = {

    val spark: SparkSession = SparkSession.builder().appName("rddtodf").master("local[1]").getOrCreate()
    val sc = spark.sparkContext
    val rdd: RDD[Row] = sc.parallelize(("lisi", 10) :: ("sz", 30) :: Nil).map {
      case (name, age) => Row(name, age)
    }
    val schema: StructType = StructType(Array(StructField("name", StringType), StructField("age", IntegerType)))
    val df: DataFrame = spark.createDataFrame(rdd, schema)
    df.show()
    spark.stop()

  }

}
